# Framework核心组件（原有的接口库）
add_library(framework INTERFACE)

target_include_directories(framework INTERFACE
    ${CMAKE_SOURCE_DIR}
)

target_link_libraries(framework INTERFACE
    nlohmann_json::nlohmann_json
)

# ========================================
# 新增：微服务RPC框架组件
# ========================================

# 服务注册中心
add_library(service_registry STATIC
    service_registry.h
    service_registry.cpp
)

target_link_libraries(service_registry
    PUBLIC
        framework
        database
        nlohmann_json::nlohmann_json
)

target_include_directories(service_registry PUBLIC
    ${CMAKE_SOURCE_DIR}
)

# 负载均衡器（头文件库）
add_library(load_balancer INTERFACE)

target_include_directories(load_balancer INTERFACE
    ${CMAKE_SOURCE_DIR}
)

# gRPC客户端
add_library(grpc_client STATIC
    grpc_client.h
    grpc_client.cpp
)

target_link_libraries(grpc_client
    PUBLIC
        framework
        service_rpc_proto
        gRPC::grpc++
        protobuf::libprotobuf
)

target_include_directories(grpc_client PUBLIC
    ${CMAKE_SOURCE_DIR}
)

# gRPC客户端连接池
add_library(grpc_client_pool STATIC
    grpc_client_pool.h
    grpc_client_pool.cpp
)

target_link_libraries(grpc_client_pool
    PUBLIC
        grpc_client
)

target_include_directories(grpc_client_pool PUBLIC
    ${CMAKE_SOURCE_DIR}
)

# ServiceBusV2（RPC客户端）
add_library(service_bus_v2 STATIC
    service_bus_v2.h
    service_bus_v2.cpp
)

target_link_libraries(service_bus_v2
    PUBLIC
        framework
        service_registry
        load_balancer
        grpc_client_pool
)

target_include_directories(service_bus_v2 PUBLIC
    ${CMAKE_SOURCE_DIR}
)

# ServiceServer（gRPC服务端）
add_library(service_server STATIC
    service_server.h
    service_server.cpp
)

target_link_libraries(service_server
    PUBLIC
        framework
        service_rpc_proto
        gRPC::grpc++
        protobuf::libprotobuf
)

target_include_directories(service_server PUBLIC
    ${CMAKE_SOURCE_DIR}
)

# 微服务框架总库（便于链接）
add_library(microservice_framework INTERFACE)

target_link_libraries(microservice_framework INTERFACE
    framework
    service_registry
    load_balancer
    grpc_client
    grpc_client_pool
    service_bus_v2
    service_server
)
